<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/temp.dwt" codeOutsideHTMLIsLocked="false" -->
<%@page import="com.crm.entity.Opportunity,com.crm.entity.Supplier,java.util.*" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<!-- InstanceEndEditable -->
<link href="<%=application.getContextPath() %>/css/css-crm.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="<%=application.getContextPath()%>/css/jquery-ui-1.8.17.custom.css"/>

<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery-1.7.2.min.js"></script>
<script language="javaScript" src="<%=application.getContextPath()%>/js/jquery-ui-1.8.20.custom.min.js"></script>
<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery.validate.js"></script>	
<script type="text/javascript" src="<%=application.getContextPath()%>/js/jquery.validate.min.js"></script>
<script language="JavaScript" src="<%=application.getContextPath()%>/js/gen_validatorv4.js"
    type="text/javascript" ></script>
<script type="text/javascript">

function getqparts(){
	var refno=$("#reflistid").val();
	if((refno==null) || (refno=="")){
		jAlert("Please Select Refrence Number ");
		return false;
	}
	else{
		var data="refno="+refno;
		 $("#ajaxLoader").show();
	$.ajax({
		url:" <%=application.getContextPath()%>/supplyOrder/getqparts.do",
		mimetype: "text/plain",
		method: "post",
		data: data,
		cache:false,
		success: function(res){
			$("#qpartres").html(res);	
		}
	}).done(function(html){
		$("#ajaxLoader").hide();
	  }).fail(function(html){
	  	$("#ajaxLoader").hide();
	  	alert("Failed To Load the Data");
	  });
	}
	}
function getpinum(){

	
	var refno=$("#reflistid").val();

	if((refno==null)|| refno==""){
		jAlert("Please Select Refrence Number");
		return false;
	}
	else{
		var data="refno="+refno;
		 $("#ajaxLoader").show();
	$.ajax({
		url:" <%=application.getContextPath()%>/supplyOrder/generatePI.do",
		mimetype: "text/plain",
		method: "post",
		data: data,
		cache:false,
		success: function(res){
			
			$("#pinumid").val(res);
			
		}
	}).done(function(html){
		$("#ajaxLoader").hide();
	  }).fail(function(html){
	  	$("#ajaxLoader").hide();
	  	alert("Failed To Load the Data");
	  });
	}
	}
</script>
<script>

	$(function() {
		$( "#datepicker1" ).datepicker({ minDate:0,dateFormat: "dd-mm-yy" },"option", "autoSize", true);
	
		//$( "#datepicker2" ).datepicker({ dateFormat: "dd-mm-yy" },"option", "autoSize", true);
		
		var today=new Date();
		var day=today.getDate();
		var month=today.getMonth();
		var year=today.getFullYear();
		var da=day+"-"+(month+1)+"-"+year;
		document.getElementById("datepicker2").value=da;
		document.getElementById("datepicker1").value=da;
		document.getElementById("soedate").value=da;
		$( "#soedate" ).datepicker({minDate:0, dateFormat: "dd-mm-yy" },"option", "autoSize", true);
	});
	</script>
	<script type="text/javascript">
    $(document).ready(function(){
       $("#form1").validate({
    	   rules:{
    		   reflist: "required",
    		   qselect: "required",
       sonumber:{
    	   required: true
       },
    		   sodate: "required",
    		   pidate: "required",
    		   soedate: "required",
    		   pinum: { 
    			   required: true
    			   }
    	   },
       messages:{
    	   reflist: "Refrence must not be empty",
    	   qselect: "Quotation No Must Not be empty",
    	   sonumber: "Supplier order must not be empty",
    	   sodate:{
    		   required: " Supplier Order Date is not empty"
    		   
    	   },
    	   pidate:{
        	   required: "PO date is  requred"
           },
           soedate:{
        	   required: "SO End Date is requred"
        	   
           },
           pinum:{
        	   required: "PI Number is Required."
        	   
           }
       }
       });
       });
    </script> 
    <script type="text/javascript">
     function bvalidate(){
       $("#form1").validate({
    	   rules:{
    		   reflist: "required",
    		   qselect: "required",
       sonumber:{
    	   required: true
       },
    		   sodate: "required",
    		   pidate: "required",
    		   soedate: "required",
    		   pinum: { 
    			   required: true
    			   }
    	   },
       messages:{
    	   reflist: "Refrence must not be empty",
    	   qselect: "Quotation No Must Not be empty",
    	   sonumber: "Supplier order must not be empty",
    	   sodate:{
    		   required: " Supplier Order Date is not empty"
    		   
    	   },
    	   pidate:{
        	   required: "PO date is  requred"
           },
           soedate:{
        	   required: "SO End Date is requred"
        	   
           },
           pinum:{
        	   required: "PI Number is Required."
        	   
           }
       }
       });  
     }
    </script> 
      <script type="text/javascript">
 function getFile(){
   document.getElementById("upfile").click();
 }
 function getbankFile(){
	   document.getElementById("bankfile").click();
	 }
 function getwarFile(){
	   document.getElementById("warfile").click();
	 }
 function sub(obj){
    var file = obj.value;
    var fileName = file.split("\\");
    document.getElementById("socdiv").innerHTML = fileName[fileName.length-1];
    //document.myForm.submit();
    //event.preventDefault();
  }
 function sub1(obj){
	    var file = obj.value;
	    var fileName = file.split("\\");
	    document.getElementById("bcdiv").innerHTML = fileName[fileName.length-1];
	   // document.myForm.submit();
	   // event.preventDefault();
	  }
 function sub2(obj){
	    var file = obj.value;
	    var fileName = file.split("\\");
	    document.getElementById("wcdiv").innerHTML = fileName[fileName.length-1];
	    //document.myForm.submit();
	   // event.preventDefault();
	  }
</script>
</head>

<body>

<div id="main">
  <%@ include file="common/header.jsp" %>
  <%@ include file="common/submenu.jsp" %>
  <div id="content">
  <div id="enqclient"  align="center" class="result_msg"></div>
  <div id="resultMsg"  align="center" class="result_msg">
    <% 
   String msg= request.getParameter("msgsrc");
    	if(msg!=null){
    		System.out.println(msg);
    		out.println(msg);
    	}
    	
    %>
    </div>
  <form id="form1" name="form1" method="post" enctype="multipart/form-data"  action="<%=application.getContextPath()%>/supplyOrder/savesupplier.do">
  
    <div id="work-area2">
      <div class="heading2">Supply Order</div>
	  <%List<Opportunity> opprtlist =(List<Opportunity>)request.getAttribute("opprtunity");%>
      <div class="boxIFS">
        
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td align="right" valign="middle">&nbsp;</td>
              <td align="right" valign="middle">&nbsp;</td>
              <td align="right" valign="middle">&nbsp;</td>
              <td align="right" valign="middle">&nbsp;</td>
              <td align="right" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
            </tr>
            <tr>
              <td width="20%" align="left" valign="middle">Reference Number</td>
              <td width="23%" align="left" valign="middle">
              <select name="reflist" class="form" id="reflistid" onchange="javascript: getqparts()">
        
                 <option value="">Please Select</option>
         <% 
              if(opprtlist!=null){
            	  System.out.println("the size of the pr list is "+opprtlist.size());
	      	for(int i=0;i<opprtlist.size();i++){
	      	%>
           <option  value="<%=opprtlist.get(i).getRefNum()%>"><%=opprtlist.get(i).getRefNum()%></option>
                   	<%	}
	              	}%>
                </select>  
                           </td>
              <td width="7%" align="right" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">Proforma Invoice Number</td>
              <td align="left" valign="top"><input name="pinum" type="text" class="form" onfocus="javascript :getpinum();" id="pinumid" /></td>
              <!-- <td width="17%" align="left" valign="middle">Quotation Number</td>
              <td width="22%" align="left" valign="middle">
              <select name="qselect" class="form" id="qselectid"> -->
              <td width="1%" align="left" valign="middle">&nbsp;</td>
              <td width="10%" align="left" valign="middle"></td>
            </tr>
            <tr>
              <td height="5" align="left"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="middle"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
            </tr>
            <tr>
              <td height="5" align="left"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="middle"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
            </tr>
            <tr>
              <td align="left" valign="middle">Supply Order Number</td>
              <td align="left" valign="top"><label>
                <input name="sonumber" type="text" class="form" id="textfield" />
              </label></td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">Proforma Invoice Date</td>
              <td align="left" valign="top"><input name="pidate" id="datepicker2" type="text" class="form" value=""/></td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
            </tr>
            <tr>
              <td height="5" align="left"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="middle"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
            </tr>
            <tr>
              <td height="5" align="left"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="middle"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
            </tr>
            <tr>
              <td align="left" valign="middle">Supply Order Start Date</td>
              <td align="left" valign="top"><input name="sodate" id="datepicker1" type="text" class="form" value=""/></td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">Supplier Order EndDate</td>
              <td align="left" valign="top"><input name="soedate" id="soedate" type="text" class="form" value=""/></td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
            </tr>
                  <tr>
              <td height="5" align="left"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="middle"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
            </tr>
                     <tr>
              <td height="5" align="left"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="middle"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
              <td height="5" align="left" valign="top"></td>
            </tr>
                  <tr>
              <td height="10" align="left" valign="top">Supply Order Copy</td>
              <td height="10" align="left" valign="top">  <div class="uploadmain" id="socdiv" onclick="getFile()">Click to upload a file</div>
						<div style='height: 0px;width: 0px; overflow:hidden;'>
                      <input id="upfile"  name="sordercopy" type="file" value="upload" onchange="sub(this)"/>
                    </div></td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
              <td align="left" valign="middle"><input name="getparts"  type="button" class="button" onclick="javascript: getqparts()"value="Search" /></td>
              <td align="left" valign="top">&nbsp;</td>
              <td align="left" valign="middle">&nbsp;</td>
            </tr>
          </table>
      
      </div>
	  <div id="ajaxLoader" style="display:none" align="center"><img src="<%=application.getContextPath()%>/images/ajax_loader.gif"/></div>
	  
	   <table style="height:300px; width:910px;" ><tr><td><div  id="qpartres" class="boxtable"></div></td></tr></table>  
    </div>
    </form>
   <!--  <div id="left-panel"></div> -->
    </div><div id="footer"></div>  
</div>
</body>
<!-- InstanceEnd --></html>
<script language="JavaScript" type="text/javascript">

$(function() {
	$( "#bgdate" ).datepicker({ dateFormat: "dd-mm-yy" },"option", "autoSize", true);
});
$(function() {
	$( "#bgedate" ).datepicker({ dateFormat: "dd-mm-yy" },"option", "autoSize", true);
});
$(function() {
	$( "#wargdate" ).datepicker({ dateFormat: "dd-mm-yy" },"option", "autoSize", true);
});
$(function() {
	$( "#waredate" ).datepicker({ dateFormat: "dd-mm-yy" },"option", "autoSize", true);
});
function  validateForm(){
	var tc=$("#tc").val();
	  if(tc==0){
		  $("#tc").val(1);
		  jAlert("Please Check the Terms And Conditions");
		  return false;
	  }
	 var frmvalidator  = new Validator("form1");
	 
 /*  var frmvalidator  = new Validator("form1"); */
  
  var rowcount=document.getElementById("rowcountid");
  var rowc=rowcount.value;
//alert("the rowcount value is"+rowc);
  for(var i=0;i<rowc;i++)
	  {
  /* frmvalidator.addValidation("partno"+i,"req","Please enter PartNo"+i+""); */
  /* frmvalidator.addValidation("partno"+i,"maxlen=30",	"Max length for partno"+i+" is 30");
  frmvalidator.addValidation("partno"+i,"alphanumeric","partno"+i+"Only alpha and Numeric chars only"); */
 
 
  
  frmvalidator.addValidation("qtyid"+i,"req","please Qty  must not be empty");
/*     frmvalidator.addValidation("source"+i,"maxlen=50","maximum  length of source"+i+" is 50"); */
  /*   frmvalidator.addValidation("source"+i,"alphabetic_space","Source"+i+" must be characters"); */
    
  frmvalidator.addValidation("upriceid"+i,"req","unitprice"+" must not be empty");
  frmvalidator.addValidation("upriceid"+i,"numeric","uvalue must be numeric");
/*   frmvalidator.addValidation("supplier"+i,"alphabetic_space"); */
  
  frmvalidator.addValidation("discountid"+i,"req","discount must not be empty");
  frmvalidator.addValidation("discountid"+i,"numeric","discount must be numeric");
  
  frmvalidator.addValidation("padisid"+i,"req","Price after discount must not be empty");
  frmvalidator.addValidation("padisid"+i,"numeric","Price after discount  must be numeric");
 
  
 
	  }
}
</script>
